package gui.awt.listener;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class TestKeyListener {
    public static void main(String[] args) {
        new KeyFrame();
    }
}

class KeyFrame extends Frame{

    public KeyFrame(){
        setBounds(100,100,400,300);
        setBackground(Color.CYAN);
        setVisible(true);

        addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                //获取键盘按的是哪个健
                System.out.println(e.getKeyCode());

                if(e.getKeyCode() == KeyEvent.VK_UP){
                    System.out.println("你按了上键");
                }
            }
        });
    }
}
